from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
import unittest
from shujuku.db import db

class A3mall(unittest.TestCase):
    def setUp(self) -> None:
        print('begin case')
        self.sql = db('10.59.9.12', 'root', 'yidong666', 'a3mall')
    def tearDown(self) -> None:
        print('end case')

    def test_A3mall_01(self):
        driver=webdriver.Edge()
        driver.get("http://10.59.9.12:7001/admin/login/index.html")
        driver.maximize_window()
        driver.find_element(By.NAME,'username').send_keys("admin")
        driver.find_element(By.NAME,'password').send_keys("admin888")
        sleep(10)
        driver.find_element(By.XPATH,'//*[@id="theForm"]/div[4]/button').click()
        sleep(5)
        denglu=driver.find_element(By.XPATH,'/html/body/div/aside/div/section/div/div[2]/p[1]').text
        print(denglu)
        sleep(2)
        # 点击会员
        driver.find_element(By.XPATH,'/html/body/div/header/nav/div[1]/ul/li[5]/a').click()
        sleep(2)
        # 搜索用户
        driver.find_element(By.XPATH,'//*[@id="search-box"]/div/div/form/div/div[2]/div/input').send_keys('18238680385')
        sleep(2)
        # 点击搜索
        driver.find_element(By.ID,'search-btn').click()
        sleep(3)
        username=driver.find_element(By.XPATH,'/html/body/div/div/section/div/div/div[2]/div[2]/table/tbody/tr/td[3]/div').text
        print(username)
        result=self.sql.chaxun("select * from mall_users where username='18238680385'")
        print(result[0][2])
        self.assertEqual(username,result)

if __name__ == '__main__':
    unittest.main()

